package com.xiaoyu.tool.entity.order;

import com.xiaoyu.tool.entity.common.AbstractEntity;
import com.xiaoyu.tool.utils.BigDecimalDealUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;

/**
 * 购物车/订单详情
 * */
@Entity
@Table(name = "line_items")
@Data
@EqualsAndHashCode(callSuper = true)
public class LineItem extends AbstractEntity {

    @Column
    private Long orderId;

    @Column
    private Long productId;

    @Column
    private Long cartId;

    @Column
    private Long productGroupId;

    @Column
    private Long formatId;

    @Column
    private Long colorId;

    @Column
    private Integer quantity = 1;

    @Column
    private BigDecimal price = new BigDecimal(0);

    public Double totalPrice(){
        return BigDecimalDealUtils.stayTwoDecimal(getPrice().multiply(new BigDecimal(getQuantity())));
    }

    public Double initTotalPrice(BigDecimal sellPrice){
        return BigDecimalDealUtils.stayTwoDecimal(sellPrice.multiply(new BigDecimal(getQuantity())));
    }

}
